package com.mycompany.testcases.chee;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import com.mycompany.project.client.ModuleType;
import com.mycompany.project.client.chee.Module;
import com.mycompany.project.client.chee.ModuleList;

public class ModuleListTest{

	
	@Before
	public void initMList()
	{
		//initialze the module list first
		ModuleList.getMlist().clear();
		ModuleList.initMList();
		
	}
	
	@Test
	public void test1() {
		//test the add method
		for(int i = 0; i < 5; i++)//adds 5 plain modules to the list
		{
			Module m = new Module();
			m.setModuleType(ModuleType.PLAIN);
			ModuleList.addModule(m);
		}
		for(int i = 0; i < 5; i++)//adds 5 control modules to the list
		{
			Module m = new Module();
			m.setModuleType(ModuleType.CONTROL);
			ModuleList.addModule(m);
		}
		for(int i = 0; i < 5; i++)//adds 5 power modules to the list
		{
			Module m = new Module();
			m.setModuleType(ModuleType.POWER);
			ModuleList.addModule(m);
		}
		for(int i = 0; i < 5; i++)//adds 5 food/water storage modules to the list
		{
			Module m = new Module();
			m.setModuleType(ModuleType.FOOD_WATER_STORAGE);
			ModuleList.addModule(m);
		}
		for(int i = 0; i < 5; i++)//adds 5 DORMITORY modules to the list
		{
			Module m = new Module();
			m.setModuleType(ModuleType.DORMITORY);
			ModuleList.addModule(m);
		}
		for(int i = 0; i < 5; i++)//adds 5 canteen modules to the list
		{
			Module m = new Module();
			m.setModuleType(ModuleType.CANTEEN);
			ModuleList.addModule(m);
		}
		for(int i = 0; i < 5; i++)//adds 5 sanitation modules to the list
		{
			Module m = new Module();
			m.setModuleType(ModuleType.SANITATION);
			ModuleList.addModule(m);
		}
		for(int i = 0; i < 5; i++)//adds 5 gym modules to the list
		{
			Module m = new Module();
			m.setModuleType(ModuleType.GYM_RELAXATION);
			ModuleList.addModule(m);
		}
		for(int i = 0; i < 5; i++)//adds 5 airlock modules to the list
		{
			Module m = new Module();
			m.setModuleType(ModuleType.AIR_LOCK);
			ModuleList.addModule(m);
		}
		for(int i = 0; i < 5; i++)//adds 5 medical modules to the list
		{
			Module m = new Module();
			m.setModuleType(ModuleType.MEDICAL);
			ModuleList.addModule(m);
		}
		//check to see if all 5 different modules are on the list and place correctly in their own list
		assertEquals(ModuleList.getMlist().get(ModuleType.PLAIN.ordinal()).size(),5);
		assertEquals(ModuleList.getMlist().get(ModuleType.CONTROL.ordinal()).size(),5);
		assertEquals(ModuleList.getMlist().get(ModuleType.POWER.ordinal()).size(),5);
		assertEquals(ModuleList.getMlist().get(ModuleType.FOOD_WATER_STORAGE.ordinal()).size(),5);
		assertEquals(ModuleList.getMlist().get(ModuleType.DORMITORY.ordinal()).size(),5);
		assertEquals(ModuleList.getMlist().get(ModuleType.CANTEEN.ordinal()).size(),5);
		assertEquals(ModuleList.getMlist().get(ModuleType.SANITATION.ordinal()).size(),5);
		assertEquals(ModuleList.getMlist().get(ModuleType.GYM_RELAXATION.ordinal()).size(),5);
		assertEquals(ModuleList.getMlist().get(ModuleType.AIR_LOCK.ordinal()).size(),5);
		assertEquals(ModuleList.getMlist().get(ModuleType.MEDICAL.ordinal()).size(),5);
		
	}
	@Test
	public void test2() {
		//test add and remove methods
		for(int i = 0; i < 20; i++)
		{
			Module m = new Module();
			m.setModuleType(ModuleType.MEDICAL);
			ModuleList.addModule(m);
			//check if it is on the list
			assertEquals(ModuleList.getMlist().get(ModuleType.MEDICAL.ordinal()).size(),1);
			//remove one medical from the list
			ModuleList.removeModule(m);
			//check if it is removed from the list
			assertEquals(ModuleList.getMlist().get(ModuleType.MEDICAL.ordinal()).size(),0);
		}
	}
	
	@Test
	public void test3(){
		//test to see if the total number of modules are reported correctly
		//first we'll make 5 usable,1 beyond repair, and 2 usable after repair modules
		//totaling up to 8 modules
		
		for(int i = 0; i < 5; i++)//adds 5 "usable" medical modules to the list
		{
			Module m = new Module();
			m.setModuleType(ModuleType.MEDICAL);
			m.setStats("usable");
			ModuleList.addModule(m);
		}
		//adds 1 beyond repair to the list
		Module m = new Module();
		m.setModuleType(ModuleType.MEDICAL);
		m.setStats("beyond repair");
		ModuleList.addModule(m);
		//add two usable after repair modules
		for(int i=0;i<2;i++)
		{
			Module t = new Module();
			t.setModuleType(ModuleType.MEDICAL);
			t.setStats("usable after repair");
			ModuleList.addModule(t);
		}
		//check if total modules beyond repair is 1
		assertEquals(ModuleList.getTotalBeyondRepairCount(),1);
		//check if total modules usable is 5
		assertEquals(ModuleList.getTotalUsableCount(),5);
		//check if total modules usable after repair is 2
		assertEquals(ModuleList.getTotalUsableAfterRepairCount(),2);
	}
	
	@Test
	public void test4(){
		//test to see if the total number of specific modules are reported correctly
		//first we'll make 5 usable,1 beyond repair, and 2 usable after repair modules
		//totaling up to 8 modules
		
		for(int i = 0; i < 5; i++)//adds 5 "usable" medical modules to the list
		{
			Module m = new Module();
			m.setModuleType(ModuleType.AIR_LOCK);
			m.setStats("usable");
			ModuleList.addModule(m);
		}
		//adds 1 beyond repair to the list
		Module m = new Module();
		m.setModuleType(ModuleType.CONTROL);
		m.setStats("beyond repair");
		ModuleList.addModule(m);
		//add two usable after repair modules
		for(int i=0;i<2;i++)
		{
			Module t = new Module();
			t.setModuleType(ModuleType.DORMITORY);
			t.setStats("usable after repair");
			ModuleList.addModule(t);
		}
		//check if total control modules beyond repair is 1
		assertEquals(ModuleList.getModuleBeyondRepair(ModuleType.CONTROL.ordinal()),1);
		//check if total air lock modules usable is 5
		assertEquals(ModuleList.getModuleUsable(ModuleType.AIR_LOCK.ordinal()),5);
		//check if total dormitory modules usable after repair is 2
		assertEquals(ModuleList.getModuleUsableAfterRepair(ModuleType.DORMITORY.ordinal()),2);
	}
	
	@Test
	public void test5(){
		//test to see whether a full or min configuration is possible
		
		//first we'll add in the minimum amount of modules require for
		//min habitat configuration to the list
		for(int i = 0; i < 3; i++)//adds 5 "usable" modules to the list
		{
			Module m = new Module();
			m.setModuleType(ModuleType.PLAIN);
			m.setStats("usable");
			ModuleList.addModule(m);
		}
		//adds one of each different module to the list and make them usable
		for(int i=1;i<10;i++)
		{
			Module t = new Module();
			t.setModuleType(Module.checkModuleType(i));
			t.setStats("usable");
			ModuleList.addModule(t);
		}
		//check configuration is now possible, 0 means no 1 means yes
		assertEquals(ModuleList.checkConfiguration(),1);
	}
	
	@Test
	public void test6(){
		//test to make sure that our configuration takes into account which modules are usable and not.
		//we'll only use usable and usable after repair modules to build the habitat.
		//beyond repair modules will not be consider!
		
		//first we'll add in the minimum amount of modules require for
		//min habitat configuration to the list
		for(int i = 0; i < 3; i++)//adds 5 "beyond repair"  modules to the list
		{
			Module m = new Module();
			m.setModuleType(ModuleType.PLAIN);
			m.setStats("usable");
			ModuleList.addModule(m);
		}
		//adds one of each different module to the list and make them usable
		for(int i=1;i<10;i++)//"beyond repair"
		{
			Module t = new Module();
			t.setModuleType(Module.checkModuleType(i));
			t.setStats("beyond repair");
			ModuleList.addModule(t);
		}
		//check configuration is now possible, 0 means no 1 means yes
		assertEquals(ModuleList.checkConfiguration(),0);
	}

}
